package com.fy.controller;

import com.fy.common.annotation.GlobalInterceptor;
import com.fy.pojo.dto.activity.ActivityListDTO;
import com.fy.pojo.entity.Activity;
import com.fy.pojo.vo.activity.ActivityVO;
import com.fy.service.ActivityService;
import com.fy.utils.result.PageResult;
import com.fy.utils.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static cn.hutool.core.bean.BeanUtil.copyProperties;

@Slf4j
@RestController
@RequestMapping("/activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    /**
     * 获取活动列表
     */
    @PostMapping("/list")
    @GlobalInterceptor
    public Result<PageResult> getActivityListByUser() {
        ActivityListDTO activityListDTO = new ActivityListDTO();
        return activityService.getActivityListAll(activityListDTO);
    }

    @PostMapping("/detail")
    @GlobalInterceptor
    public Result getActivityDetail(@RequestParam("id") Long id) {
        log.info("获取活动详情，id={}", id);
        Activity activity = activityService.getById(id);
        ActivityVO activityVO = new ActivityVO();
        copyProperties(activity, activityVO);
        activityVO.setStartTime(activity.getStartTime().toString());
        activityVO.setEndTime(activity.getEndTime().toString());
        return Result.success(activityVO);
    }
}
